﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Linker.TaskCenter.Services;
using Volo.Abp.Domain.Entities.Auditing;

namespace Linker.TaskCenter.Tasks.Entity
{
    [Table("Tasks")]
    public class TaskEntity : CreationAuditedEntity<Guid>
    {
        public TaskEntity()
        {
            ResponseResult = TaskResponseResultEnum.Unknown;
            Status = TaskStatusEnum.InQueue;
            Retry = 0;
        }

        [Required] public virtual Guid ServiceId { get; set; }

        [ForeignKey("ServiceId")] public virtual ServiceEntity Service { get; set; }

        /// <summary>
        ///     请求参数
        /// </summary>
        [MaxLength]
        public virtual string Request { get; set; }

        /// <summary>
        ///     响应
        /// </summary>
        [MaxLength]
        public virtual string Response { get; set; }

        /// <summary>
        ///     任务执行结果
        /// </summary>
        public virtual TaskResponseResultEnum ResponseResult { get; set; }

        /// <summary>
        ///     任务异常
        /// </summary>
        [MaxLength]
        public virtual string Error { get; set; }

        /// <summary>
        ///     任务状态
        /// </summary>
        public virtual TaskStatusEnum Status { get; set; }

        /// <summary>
        ///     任务完成回调
        /// </summary>
        [StringLength(255)]
        public virtual string CallbackUrl { get; set; }

        /// <summary>
        ///     任务完成回调结果
        /// </summary>
        public virtual string CallbackResult { get; set; }

        /// <summary>
        ///     任务名称
        /// </summary>
        [Required]
        [StringLength(128)]
        public virtual string Name { get; set; }

        /// <summary>
        ///     任务备注
        /// </summary>
        [StringLength(128)]
        public virtual string Remark { get; set; }

        /// <summary>
        ///     重试次数
        /// </summary>
        public virtual int Retry { get; set; }

        /// <summary>
        ///     创建人
        /// </summary>
        public virtual string Creator { get; set; }
    }
}